package com.ventasimple.dao;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.ventasimple.modelo.Direccion;
import java.io.Serializable;
import java.util.List;


/**
 *
 * @author ctrosch
 */

public class DireccionDAO extends BaseDAO<Direccion> implements Serializable {
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    public Direccion getDireccion(int id){

        return getObjeto(Direccion.class, id);
    }

    public List<Direccion> getLista(boolean  activos){
        
        try {
            
            String sQuery = "SELECT m FROM Direccion m "                
                + (activos ? " WHERE m.activo = 'S'" : "" )
                +" ORDER BY m.descripcion";                       
                        
            return execQueryList(sQuery);
            
        } catch (Exception e) {
            
            System.err.print("ERROR: " + e.getMessage());
            return null;
        }
    }
    
    public List<Direccion> getListaByTipoPublicacion(int idTipo, boolean  activos){
        
        try {
            
            String sQuery = "SELECT m FROM Direccion m "                
                + " WHERE m.tipoPublicacion.id =  " + idTipo
                + (activos ? " AND m.activo = 'S'" : "" )
                +" ORDER BY m.descripcion";                       
                        
            return execQueryList(sQuery);
            
        } catch (Exception e) {
            
            System.err.print("ERROR: " + e.getMessage());
            return null;
        }
    }
}
